package com.ruoyi.baselibrary.infobasecase.service.impl;

import java.util.List;

import com.ruoyi.baselibrary.infobasecategory.domain.InfoBaseCategory;
import com.ruoyi.baselibrary.infobasecategory.mapper.InfoBaseCategoryMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.baselibrary.infobasecase.mapper.InfoBaseCaseMapper;
import com.ruoyi.baselibrary.infobasecase.domain.InfoBaseCase;
import com.ruoyi.baselibrary.infobasecase.service.IInfoBaseCaseService;

/**
 * 案例库Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-01-05
 */
@Service
public class InfoBaseCaseServiceImpl implements IInfoBaseCaseService 
{
    @Autowired
    private InfoBaseCaseMapper infoBaseCaseMapper;

    @Autowired
    private InfoBaseCategoryMapper infoBaseCategoryMapper;

    @Autowired
    private ISysUserService iSysUserService;

    /**
     * 查询案例库
     * 
     * @param id 案例库主键
     * @return 案例库
     */
    @Override
    public InfoBaseCase selectInfoBaseCaseById(Long id)
    {
        return infoBaseCaseMapper.selectInfoBaseCaseById(id);
    }

    /**
     * 查询案例库列表
     * 
     * @param infoBaseCase 案例库
     * @return 案例库
     */
    @Override
    public List<InfoBaseCase> selectInfoBaseCaseList(InfoBaseCase infoBaseCase)
    {
        List<InfoBaseCase> infoBaseCases = infoBaseCaseMapper.selectInfoBaseCaseList(infoBaseCase);
        for (InfoBaseCase baseCase : infoBaseCases) {
            InfoBaseCategory infoBaseCategory = infoBaseCategoryMapper.selectInfoBaseCategoryById(baseCase.getCaseClassify());
            SysUser sysUser = iSysUserService.selectUserById(baseCase.getUploadBy());
            baseCase.setClassifyName(infoBaseCategory.getCategoryName());
            baseCase.setUploadName(sysUser.getNickName());
        }
        return infoBaseCases;
    }

    /**
     * 新增案例库
     * 
     * @param infoBaseCase 案例库
     * @return 结果
     */
    @Override
    public int insertInfoBaseCase(InfoBaseCase infoBaseCase)
    {

        infoBaseCase.setUploadBy(SecurityUtils.getUserId());
        return infoBaseCaseMapper.insertInfoBaseCase(infoBaseCase);
    }

    /**
     * 修改案例库
     * 
     * @param infoBaseCase 案例库
     * @return 结果
     */
    @Override
    public int updateInfoBaseCase(InfoBaseCase infoBaseCase)
    {
        return infoBaseCaseMapper.updateInfoBaseCase(infoBaseCase);
    }

    /**
     * 批量删除案例库
     * 
     * @param ids 需要删除的案例库主键
     * @return 结果
     */
    @Override
    public int deleteInfoBaseCaseByIds(Long[] ids)
    {
        return infoBaseCaseMapper.deleteInfoBaseCaseByIds(ids);
    }

    /**
     * 删除案例库信息
     * 
     * @param id 案例库主键
     * @return 结果
     */
    @Override
    public int deleteInfoBaseCaseById(Long id)
    {
        return infoBaseCaseMapper.deleteInfoBaseCaseById(id);
    }
}
